package main

import (
	"bufio"
	"os"
	"fmt"
	"io"
)
//不能用来copy 文本文件
func main() {
	written,err := CopyFile("./2.jpg","./1.jpg")
	if err != nil {
		fmt.Printf("错误是%v",err)
	}
	fmt.Println(written)
}

func CopyFile(dstFileName string,srcFileName string) (written int64,err error){
	srcFile,err := os.Open(srcFileName)
	defer srcFile.Close()
	if err != nil {
		fmt.Println(err)
	}
	reader := bufio.NewReader(srcFile)
	dstFile,err1 := os.OpenFile(dstFileName,os.O_WRONLY | os.O_CREATE,0666)
	defer dstFile.Close()
	if err1 != nil {
		fmt.Println(err1)
	}
	writer := bufio.NewWriter(dstFile)
	return io.Copy(writer,reader)
}